package org.deltaset.secured.example;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderColumn;

/**
 *
 * @author dmakariev
 */
@Entity
public class JoinedParent extends AbstractParent<JoinedParent,JoinedChild>{

    //@OneToMany - there is Hibernate bug, the workaround is to use ManyToMany https://hibernate.onjira.com/browse/HHH-1268
    @ManyToMany( fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinTable(name="my_joined_parent_child")
    @OrderColumn( name="CHILD_INDEX"  )
    private List<JoinedChild> children;

    @Override
    public List<JoinedChild> getChildren() {
        if(null==children){
            children = new ArrayList<JoinedChild>();
        }
        return children;
    }

    @Override
    public JoinedChild newChild(String childName) {
       return new JoinedChild(childName);
    }

    @Override
    public JoinedParent addNumberOfChildren(int numberOfChildren) {
        return super.addChildren(numberOfChildren);
    }
    
}
